<?php
class Default_Model_Answer extends Zend_Db_Table{

	protected $_name="tblanswer";
	protected $_primary="id";
	protected $db;
	public function __construct(){
		parent::__construct();
		$this->db= Zend_Registry::get('connectDb');
	}
	public function count(){
		$select = $this->db->select()->from('tblanswer AS a',array('COUNT(a.id) AS totalItem'));
		$result=	$this->db->fetchOne($select);
		return $result;
	}

	public function getItem($param=null,$option=null){
		$select= $this->db->select->from('tblanswer AS a');
		if($option['task'] == 'all-answer'){
			$select->joinLeft('tbluser AS u','u.id=a.id_user',array('u.*'))
					->joinLeft('tblquestion AS q','q.id=a.id_question',array('q.*'));
			return $this->db->fetchAll($select);
		}
		if($option['task']=='list-answer'){
			$select->joinLeft('tbluser AS u','u.id=a.id_user',array('u.*'))
					->jointLeft('tblquestion AS q','q.id=a.id_question',array('q.*'))
					->where('a.id_question='.$param['id_question']);
			return $this->db->fetchAll($select);
		}
	}
	public function saveItem(){
		
	}
}